package com.ultrawise.survey.common.printfile;

import com.ultrawise.survey.contants.SurveyConstants;

public class TypeToHtml {

	private static final String CHECKBOXSTAR = "<input type='checkbox' ";
	private static final String RADIOBOXSTAR = "<input type='radio' ";

	private static final String OPTIONEND = " />";
	private static final String OPTIONNAME = "ob";

	/***
	 * 根据类型编号返回对应的html信息
	 * 
	 * @param type
	 * @return
	 */
	public static String getHtmlByType(String type, String option, Integer opid) {
		String ophtml = "";
		if (type != null && type.length() > 0) {
			String[] spst = option.split(SurveyConstants.SURVEY_DATAINFO_SPACE);
			for (int i = 0; spst != null && i < spst.length; i++) {
				ophtml += getOption(spst[i], type, String.valueOf(i+1), opid);
			}
			if("2".equalsIgnoreCase(type) || "4".equalsIgnoreCase(type))
				ophtml+="<br>具体说明：<input name='oth_"+ opid +"' type='text'  size='100'/>";
			else if("5".equalsIgnoreCase(type))
				ophtml+="具体说明：<input name='oth_"+ opid +"' type='text'  size='100' id='fx_"+opid+"' maxlength='200'/>";
		}
		return ophtml;
	}

	/***
	 * 各个题目选项的显示HTML内容
	 * 
	 * @param option
	 * @param type
	 * @param order
	 * @param opid
	 * @return
	 */
	private static String getOption(String option, String type, String order, Integer opid) {
		String ophtml = "";
		//1为单选
		if("3".equalsIgnoreCase(type)||"4".equalsIgnoreCase(type)){
			ophtml += CHECKBOXSTAR + " name='fx_" + opid + "' value='ob"+order+"'  id='fx_" + opid + "'" + OPTIONEND + option;
		}else if("1".equalsIgnoreCase(type)||"2".equalsIgnoreCase(type)){//3为复选
			ophtml += RADIOBOXSTAR + " name='dx_" + opid + "' value='ob"+order+"'  id='fx_" + opid + "' " + OPTIONEND + option;
		}else{
		}
		return ophtml;
	}

}
